BZIP2_COMPRESS

The BZIP2_COMPRESS function compresses a given input array using the bzip2 compression algorithm, and returns a byte array containing the compressed data along with the metadata describing the compressed data. The compression is done using the IDL-Python bridge to access the Python bz2 library.

The compressed data can be uncompressed using the BZIP2_UNCOMPRESS function.

Examples

Here, we compress and uncompress a float array just like in ZLIB_COMPRESS:

data = findgen(100, 200)

zdata = bzip2_compress(data)

help, zdata

dataout = bzip2_uncompress(zdata, TYPE=4, DIMENSIONS=[100, 200])

print, array_equal(dataout, data)

IDL prints:

zdata BYTE = Array[18282]

1

Since the float array has a total of 80,000 bytes, the compression space savings is about 77%.

Syntax

Result = bzip2_compress( Array[, COMPRESS_LEVEL=value] )

Arguments

Array

Set this argument to an array of any IDL numeric type or a string.

Keywords

COMPRESS_LEVEL

Set this keyword to an integer in the range 1-9 giving the desired compression level. A value of 1 gives the least compression, while 9 (default) gives the most compression.

Note: Note that for low compression levels (or highly-random data), the size of the compressed result may be larger than the original data.

Version History

9.2.0

Introduced

See Also

ZLIB_COMPRESS, ZLIB_UNCOMPRESS, BZIP2_UNCOMPRESS